//
//  mainTabbar.swift
//  微博项目
//
//  Created by zhaoyinpeng on 16/3/6.
//  Copyright © 2016年 zhaoyinpeng. All rights reserved.
//

import UIKit

class mainTabbar: UITabBar {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(plusBtn)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
   //.自定义tabbar的大小
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //.子视图有哪些视图
        
        //.UITabBatButton 是私有属性
//        print(subviews)
        
        
        //.确定tabbarButton大小
        let w = self.bounds.width / 5
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        
     
        
        var index: CGFloat = 0
        //遍历子视图  获取 UITabBarButton
        for subView in subviews {
            
            //.保证 通过UITabBatButton 字符串 可以获取对应的类型
            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                //.修改frame
                subView.frame = CGRectOffset(rect, index * w, 0)
                
//                if index == 1 {
//                    index++
//                }
                
                //.三目运算符
                index += (index == 1 ? 2 : 1)
            }
        }
        
            //.设置加号按钮的位置
        
//        addSubview(plusBtn)
        plusBtn.frame = CGRectOffset(rect, 2*w, 0)
    }
    
       //.懒加载视图
    
    lazy var plusBtn: UIButton = UIFactory.buttonWithImage("tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
    

}
